package com.icee.myth.manager.pipelineFactory;

import com.icee.myth.manager.channelHandler.HttpServerHandlerToWeb;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;


/**
 *
 * @author yangyi
 */
public class HttpServerToWebPipelineInitializer extends ChannelInitializer<SocketChannel> {

    final static EventExecutorGroup e1 = new DefaultEventExecutorGroup(8);

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // Uncomment the following line if you want HTTPS
        //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
        //engine.setUseClientMode(false);
        //pipeline.addLast("ssl", new SslHandler(engine));

        ch.pipeline().addLast("decoder", new HttpRequestDecoder());
        // Uncomment the following line if you don't want to handle HttpChunks.
        ch.pipeline().addLast("aggregator", new HttpObjectAggregator(1048576));   //new HttpChunkAggregator(1048576));
        ch.pipeline().addLast("encoder", new HttpResponseEncoder());
        // Remove the following line if you don't want automatic content compression.
        //pipeline.addLast("deflater", new HttpContentCompressor());
        ch.pipeline().addLast("chunkedWriter", new ChunkedWriteHandler());
        ch.pipeline().addLast(e1, new HttpServerHandlerToWeb());
    }

}
